﻿/* 
 * FileName:    Ticker.cs
 * Author:      gaohongwei<gaohongwei@bjdaxiang.cn>
 * CreateTime:  2016/5/23 13:49:53
 * Version:     v1.0
 * Description:
 * */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ET.Score.SharedLibrary
{
    public sealed class Ticker : IDisposable
    {
        private static Lazy<Ticker> instanceLazy = new Lazy<Ticker>(() => new Ticker());

        public static Ticker Instance
        {
            get { return instanceLazy.Value; }
        }

        private Timer tickTimer;

        private Ticker()
        {
            this.tickTimer = new Timer(OnTimeChanged, null, 0, 1000);
        }

        public event EventHandler TimeChanged;

        private void OnTimeChanged(object state)
        {
            EventHandler handler = TimeChanged;
            if (handler != null)
                handler(this, EventArgs.Empty);
        }

        //public void Start()
        //{
        //    tickTimer.Change(0, 1000);
        //}

        //public void Stop()
        //{
        //    tickTimer.Change(Timeout.Infinite, Timeout.Infinite);
        //}

        public void Dispose()
        {
            IDisposable disposable = tickTimer;
            disposable.Dispose();
        }
    }
}
